package com.example.demo.controller.wx;

import com.example.demo.service.face.impl.FaceRegServiceImpl;
import com.example.demo.util.FileUtil;
import com.example.demo.vo.ResultVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Description:
 * @author: liyuan
 * @data 2020-11-25 10:08
 */
@RestController
@RequestMapping("/")
public class WxFaceRegController {
    @Value("${test.rootPath}")
    private String rootPath;
    @Value("${test.projectDir}")
    private String projectDir;
    private Logger logger = LoggerFactory.getLogger(WxFaceRegController.class);
    @Autowired
    private FaceRegServiceImpl faceRegService;

    @PostMapping("FaceReg")
    public ResultVO recognizie(@RequestParam("picture") MultipartFile picture) throws IOException, InterruptedException {
        String fileUrl = FileUtil.uploadFile(picture, rootPath, projectDir,
                "Face", "Reg");
        String pictureUrl = rootPath + fileUrl;
        logger.info("图片位置：{}", pictureUrl);
        return new ResultVO(1000, faceRegService.recognizie(pictureUrl));
    }
}
